<?php

if (!isset($_POST['username'])
    || !isset($_POST['firstName'])
    || !isset($_POST['lastName'])
    || !isset($_POST['email'])
    || !isset($_POST['googleId'])
) {
    echo("Missing parameters from add");
    exit();
}
$name = $_POST['username'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$googleId = $_POST['googleId'];

// import database connection variables and connectToMysql method
require_once __DIR__ . '/db_config.php';

$mysqli = connectToMysql();

$query = "INSERT INTO User ( username, firstName, lastName, email, googleId) VALUES ( '$name', '$firstName', '$lastName', '$email', '$googleId')";

if ($result = $mysqli->query($query)) {
    /* fetch object array */
    echo json_encode($mysqli->insert_id, JSON_NUMERIC_CHECK);
} else {
    print mysqli_error($mysqli);
}

/* close connection */
$mysqli->close();
?>